package com.zxg.zbc.dal.dao.ibatis;

import java.util.List;

import com.taobao.common.dao.persistence.DBRoute;
import com.taobao.common.dao.persistence.SqlMapBaseDAO;
import com.zxg.zbc.dal.dao.UserAliPayTradeDao;
import com.zxg.zbc.dal.dao.exception.DAOException;
import com.zxg.zbc.dal.dataobject.UserAlipayTrade;

public class UserAlipayTradeDAOImpl extends SqlMapBaseDAO implements UserAliPayTradeDao {

  @Override
  public long insert(UserAlipayTrade item) throws DAOException {
    try {
      this.executeInsert("UserAlipayTrade.insertUserAlipayTradeDO", item, DBRoute.getAssistantRoute());
      return item.getId();
    } catch (Exception e) {
      throw new DAOException("UserAlipayTrade", e);
    }
  }

  @Override
  public long update(UserAlipayTrade item) throws DAOException {
    try {
      return this.executeUpdate("UserAlipayTrade.updateById", item, DBRoute.getAssistantRoute());
    } catch (Exception e) {
      throw new DAOException("UserAlipayTrade.updateById", e);
    }
  }

  @Override
  public UserAlipayTrade getById(Long id) throws DAOException {
    try {

      return (UserAlipayTrade) this.executeQueryForObject("UserAlipayTrade.selectById", id, DBRoute.getAssistantRoute());
    } catch (Exception e) {
      throw new DAOException("UserAlipayTrade.selectById", e);
    }
  }

  @SuppressWarnings("unchecked")
  @Override
  public List<UserAlipayTrade> getTradesByUserId(Long userId) throws DAOException {
    try {

      return (List<UserAlipayTrade>) this.executeQueryForList("UserAlipayTrade.selectByUserId", userId, DBRoute.getAssistantRoute());
    } catch (Exception e) {
      throw new DAOException("getTradesByUserId", e);
    }
  }

}
